package com.haixiaoke.saas.enterprise.maintenance.controller;

import java.util.List;
import javax.validation.Valid;

import com.haixiaoke.saas.common.annotation.RepeatSubmit;
import com.haixiaoke.saas.common.annotation.TenantScope;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.tenant.TenantContext;
import com.haixiaoke.saas.maintenance.domain.MaintenanceItem;
import com.haixiaoke.saas.maintenance.service.IMaintenanceItemService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 维修项目信息Controller
 *
 * @author xiaolong
 * @date 2024-09-03
 */
@RestController
@RequestMapping("/enterprise/maintenance/item")
public class EnterpriseMaintenanceItemController extends BaseController {
    @Autowired
    private IMaintenanceItemService maintenanceItemService;

    /**
     * 查询维修项目信息列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterpriseItem:list')")
    @GetMapping("/list")
    @TenantScope
    public TableDataInfo list(MaintenanceItem maintenanceItem) {
        startPage();
        maintenanceItem.setTenantId(TenantContext.getTenantId());
        List<MaintenanceItem> list = maintenanceItemService.selectMaintenanceItemList(maintenanceItem);
        return getDataTable(list);
    }

    /**
     * 根据楼盘id查询维修项目信息和公开信息
     */
    @GetMapping("/Info")
    @TenantScope
    public AjaxResult Info(MaintenanceItem maintenanceItem) {
        maintenanceItem.setTenantId(TenantContext.getTenantId());
        return success(maintenanceItemService.selectMaintenanceItemInfo(maintenanceItem));
    }

    /**
     * 获取维修项目信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterpriseItem:query')")
    @GetMapping(value = "/{maintenanceItemId}")
    public AjaxResult getInfo(@PathVariable("maintenanceItemId") Long maintenanceItemId) {
        return success(maintenanceItemService.selectMaintenanceItemByMaintenanceItemId(maintenanceItemId));
    }

    /**
     * 新增维修项目信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterpriseItem:add')")
    @PostMapping
    @TenantScope
    @RepeatSubmit
    public AjaxResult add(@RequestBody @Valid MaintenanceItem maintenanceItem) {
        maintenanceItem.setCreateBy(getUsername());
        maintenanceItem.setTenantId(TenantContext.getTenantId());
        return toAjax(maintenanceItemService.addMaintenanceItem(maintenanceItem));
    }

    /**
     * 修改维修项目信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterpriseItem:edit')")
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@RequestBody MaintenanceItem maintenanceItem) {
        maintenanceItem.setUpdateBy(getUsername());
        return toAjax(maintenanceItemService.editMaintenanceItem(maintenanceItem));
    }

    /**
     * 删除维修项目信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterpriseItem:remove')")
	@DeleteMapping("/{maintenanceItemIds}")
    @RepeatSubmit
    public AjaxResult remove(@PathVariable Long[] maintenanceItemIds) {
        return toAjax(maintenanceItemService.deleteMaintenanceItemByMaintenanceItemIds(maintenanceItemIds));
    }
}
